/*
 * @lc app=leetcode.cn id=1823 lang=typescript
 *
 * [1823] 找出游戏的获胜者
 */

// @lc code=start
function findTheWinner(n: number, k: number): number {
    const arr = [...new Array(n).keys()]
    const res = loopp(arr, k, 0);
    return res + 1;
};

function loopp(arr: any, k: any, index: any): number {
    if (arr.length === 1) {
        return arr[0];
    }
    index = (index - 1 + k) % arr.length;
    arr.splice(index, 1);
    return loopp(arr, k, index)
}

// @lc code=end

